package com.BEASTMODE.libs;

import android.opengl.GLES20;



public class CShader {
	private int shaderHandle;
	
	private int positionHandle;
	private int mvpMatHandle;
	private int texCoord;
	private int texture0;
	
	public int Position()
	{
		return positionHandle;
	}
	
	public int MVPMat()
	{
		return mvpMatHandle;
	}
	
	public int TexCoord()
	{
		return texCoord;
	}
	
	public int Texture0()
	{
		return texture0;
	}
	
	
	public void Activate()
	{
		GLES20.glUseProgram(shaderHandle);
	}
	
	public void LoadShader(String vertShaderText, String fragShaderText)
	{
		int vertShader = LoadShaderFile(vertShaderText, GLES20.GL_VERTEX_SHADER);
		int fragShader = LoadShaderFile(fragShaderText, GLES20.GL_FRAGMENT_SHADER);
		
		shaderHandle = GLES20.glCreateProgram();
		GLES20.glAttachShader(shaderHandle, vertShader);
		GLES20.glAttachShader(shaderHandle, fragShader);
		GLES20.glLinkProgram(shaderHandle);
		
		positionHandle = GLES20.glGetAttribLocation(shaderHandle, "vPos");
		mvpMatHandle = GLES20.glGetUniformLocation(shaderHandle, "MVPMat");
		texture0 = GLES20.glGetUniformLocation(shaderHandle, "textureUnit0");
		texCoord = GLES20.glGetAttribLocation(shaderHandle, "vTex");
		
	}
	
	private int LoadShaderFile(String shaderText, int type)
	{
		int handl = GLES20.glCreateShader(type);
		
		GLES20.glShaderSource(handl, shaderText);
		GLES20.glCompileShader(handl);
		
		return handl;
	}
}
